$(document).ready( function(){
	$("#addComment").on("click", function(){
		if($(this).attr("product_id"))
		{
			var useID = $(this).attr("product_id");
			var useAttr = "product";
		}
		else if($(this).attr("article_id"))
		{
			var useID = $(this).attr("article_id");
			var useAttr = "article";
		}
		
		$("#comment_type").val(useAttr);
		$("#item_id").val(useID);
		
		$("#addCommentDialog").modal("show");
		return false;
	});
	
	$("#submitComment").on("click", function(){
		$("#ajaxLoader").show();
		
		dataString = $("#addCommentDialog form").serialize();
		dataString += "&sumbit_comment=1";
		
		$.ajax({
			type:'POST',
			url: scriptsURL+"libs/ajax/ajax-includes.php",
			data: dataString,
			success: function(responseJSON){
				response = JSON.parse(responseJSON);
				var message = "";
				if(response.error_count > 0)
				{
					if(response.errors)
					{
						
						$.each(response.errors, function(index,value){
							$("#addCommentDialog form").find("input[name="+index+"], textarea[name="+index+"]").parent().addClass("has-error");
							message += '<div class="alert alert-danger">'+value+'</div>';
						});
					}
				}
				else
				{
					if(response.success)
					{
						message += '<div class="alert alert-success"><span class="glyphicon glyphicon-ok-sign"></span>'+response.success+'</div>';
						
						$("#addCommentDialog").modal("hide");
					}
				}
				$("#messageDialog .modal-body").html(message);
				$('#messageDialog').modal('show');
				$("#ajaxLoader").hide();
			}
		});
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	$("#addQuestion").on("click", function(){
		if($(this).attr("product_id"))
		{
			var useID = $(this).attr("product_id");
			var useAttr = "product";
		}
		
		$("#addQuestionDialog #product_id").val(useID);
		
		$("#addQuestionDialog").modal("show");
		return false;
	});
	
	$("#submitQuestion").on("click", function(){
		$("#ajaxLoader").show();
		
		dataString = $("#addQuestionDialog form").serialize();
		dataString += "&sumbit_question=1";
		
		$.ajax({
			type:'POST',
			url: scriptsURL+"libs/ajax/ajax-includes.php",
			data: dataString,
			success: function(responseJSON){
				response = JSON.parse(responseJSON);
				var message = "";
				if(response.error_count > 0)
				{
					if(response.errors)
					{
						$.each(response.errors, function(index,value){
							$("#addQuestionDialog form").find("input[name="+index+"], textarea[name="+index+"]").parent().addClass("has-error");
							message += '<div class="alert alert-danger">'+value+'</div>';
						});
					}
				}
				else
				{
					if(response.success)
					{
						message += '<div class="alert alert-success"><span class="glyphicon glyphicon-ok-sign"></span>'+response.success+'</div>';
						
						$("#addQuestionDialog").modal("hide");
					}
				}
				$("#messageDialog .modal-body").html(message);
				$('#messageDialog').modal('show');
				$("#ajaxLoader").hide();
			}
		});
	});
	
	
	
	
	
	
	
	
});
